package cn.iocoder.yudao.module.robot.controller.admin.agent;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;


import cn.iocoder.yudao.module.robot.controller.admin.agent.vo.*;
import cn.iocoder.yudao.module.robot.dal.dataobject.agent.RobotAgentDO;
import cn.iocoder.yudao.module.robot.service.agent.RobotAgentService;

@Tag(name = "管理后台 - 机器人坐席")
@RestController
@RequestMapping("/robot/agent")
@Validated
public class RobotAgentController {

    @Resource
    private RobotAgentService robotAgentService;

    @PostMapping("/create")
    @Operation(summary = "创建机器人坐席")
    @PreAuthorize("@ss.hasPermission('robot:agent:create')")
    public CommonResult<Long> createAgent(@Valid @RequestBody RobotAgentSaveReqVO createReqVO) {
        return success(robotAgentService.createAgent(createReqVO));
    }


    @GetMapping("/get")
    @Operation(summary = "获得机器人坐席")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('robot:agent:query')")
    public CommonResult<RobotAgentRespVO> getAgent(@RequestParam("id") Long id) {
        RobotAgentDO agent = robotAgentService.getAgent(id);
        return success(BeanUtils.toBean(agent, RobotAgentRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得机器人坐席分页")
    @PreAuthorize("@ss.hasPermission('robot:agent:query')")
    public CommonResult<PageResult<RobotAgentRespVO>> getAgentPage(@Valid RobotAgentPageReqVO pageReqVO) {
        PageResult<RobotAgentDO> pageResult = robotAgentService.getAgentPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, RobotAgentRespVO.class));
    }


}